package net.modul.customer.action;

import java.util.ArrayList;
import java.util.List;

import net.common.action.GeneralAction;
import net.modul.customer.service.CustomerDefinedService;
import net.modul.customer.service.CustomerDeleteService;
import net.modul.customer.service.CustomerEditorService;
import net.modul.customer.service.CustomerFindService;
import net.modul.customer.service.CustomerSaveDefinedService;
import net.modul.customer.service.CustomerSearchService;
import net.modul.customer.vo.CustomerVo;
import net.modul.customer.vo.FieldVo;

public class CustomerAction extends GeneralAction {

	private static final long serialVersionUID = 7127573666355745443L;

	private CustomerVo bean = new CustomerVo();
	private List<CustomerVo> list = new ArrayList<CustomerVo>();
	private List<FieldVo> fields = new ArrayList<FieldVo>();
	
	public String search() throws Exception {
		CustomerSearchService service = new CustomerSearchService();
		service.setPageBean(pageBean);
		service.invoke();
		list = service.getList();
		return SUCCESS;
	}
	
	public String editor() throws Exception {
		CustomerEditorService service = new CustomerEditorService();
		service.setBean(bean);
		service.invoke();
		return SUCCESS;
	}
	
	public String find() throws Exception {
		if(bean.getCust_id() != null) {			
			CustomerFindService service = new CustomerFindService();
			service.setId(bean.getCust_id());
			service.invoke();
			bean = service.getBean();
		}
		return SUCCESS;
	}
	
	public String delete() throws Exception {
		CustomerDeleteService service = new CustomerDeleteService();
		service.setBean(bean);
		service.invoke();
		return SUCCESS;
	}
	
	public String defined() throws Exception {
		CustomerDefinedService service = new CustomerDefinedService();
		service.setCust_id(bean.getCust_id());
		service.invoke();
		fields = service.getFields();
		return SUCCESS;
	}
	
	public String saveDefined() throws Exception {
		CustomerSaveDefinedService service = new CustomerSaveDefinedService();
		service.setCust_id(bean.getCust_id());
		service.setFields(fields);
		service.invoke();
		return SUCCESS;
	}
	
	public CustomerVo getBean() {
		return bean;
	}
	public void setBean(CustomerVo bean) {
		this.bean = bean;
	}
	public List<CustomerVo> getList() {
		return list;
	}
	public void setList(List<CustomerVo> list) {
		this.list = list;
	}

	public List<FieldVo> getFields() {
		return fields;
	}

	public void setFields(List<FieldVo> fields) {
		this.fields = fields;
	}
}
